home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / 3812A.ASM next >
Assembly Source File  |  1992-12-08  |  11KB  |  534 lines

  1. ;$Author:   DCODY  $
  2. ;$Date:   08 Dec 1992 16:50:28  $
  3. ;$Header:   X:/sccs/fm/3812a.asv   1.6   08 Dec 1992 16:50:28   DCODY  $
  4. ;$Log:   X:/sccs/fm/3812a.asv  $
  5. ;  
  6. ;     Rev 1.6   08 Dec 1992 16:50:28   DCODY
  7. ;  moved externADDR macro for Borlands link
  8. ;  
  9. ;     Rev 1.5   20 Oct 1992 11:10:42   DCODY
  10. ;  adjusted tiny model .data declaration
  11. ;  
  12. ;     Rev 1.4   24 Sep 1992 08:51:56   DCODY
  13. ;  changed MVGetHardware to mvGetHardware
  14. ;  
  15. ;     Rev 1.3   20 Jul 1992 11:40:56   DCODY
  16. ;  call to mvGetHWVersion requests active I/O detection.
  17. ;  
  18. ;     Rev 1.2   17 Jul 1992 13:55:46   DCODY
  19. ;  base I/O address can now move...
  20. ;  
  21. ;     Rev 1.1   27 Jun 1992 14:47:08   DCODY
  22. ;  fixed FMsplit for the opl3, and outdual3812 now programs one
  23. ;  side of the OPL3 at a time.
  24. ;  
  25. ;     Rev 1.0   26 Jun 1992 14:21:58   BCRANE
  26. ;  Initial revision.
  27. ;  
  28. ;     Rev 1.3   26 Jun 1992 14:12:08   DCODY
  29. ;  added the parameter to the gethwversion call.
  30. ;  
  31. ;     Rev 1.2   25 Jun 1992 21:11:10   DCODY
  32. ;  finished the init routine. Made timing loops variable based
  33. ;  upon the installed FM chip.
  34. ;  
  35. ;     Rev 1.1   23 Jun 1992 16:32:30   DCODY
  36. ;  PAS2 update
  37. ;  
  38. ;     Rev 1.0   15 Jun 1992 09:39:46   BCRANE
  39. ;  Initial revision.
  40. ;$Logfile:   X:/sccs/fm/3812a.asv  $
  41. ;$Modtimes$
  42. ;$Revision:   1.6  $
  43.  
  44.         Title 3812/OPL3 Access Routines
  45.  
  46. ;   /*\
  47. ;---|*|---===< 3821A.ASM >====----
  48. ;---|*|
  49. ;---|*| This is the output routine to write data to the twin 3821 chips,
  50. ;---|*| or OPL-3 4OP synth chip.
  51. ;---|*|
  52. ;---|*| Media Vision, Inc. Copyright (c) 1991,1992. All Rights Reserved.
  53. ;---|*|
  54. ;   \*/
  55.  
  56.     .xlist
  57.     include model.inc
  58.         include masm.inc
  59.     include state.inc
  60.         include target.inc
  61.     include common.inc
  62.     .list
  63.  
  64. if MODELSIZE eq 0
  65.     .code
  66. else
  67.     .data
  68. endif
  69.  
  70.     externADDR   mvGetHWVersion
  71.     externADDR   MVInitStatePtr
  72.  
  73.     extrn    _MVHWVersionBits   :word
  74.     extrn    _MVTranslateCode   :word
  75.     extrn    mvhwShadowPointer  :dword
  76.  
  77. indexwrite    dw    05        ; 3812 index write delays
  78. datawrite       dw      35              ; 3812 data write delays
  79. splitmode    db    0        ; 00 = mono, 01 = stereo
  80.  
  81.     .code
  82.  
  83. ;
  84. ;   /*\
  85. ;---|*|---===< mvFMInitMode (int) >====----
  86. ;---|*|
  87. ;---|*| This routine initializes the Dual 3812/OPL-3 chip
  88. ;---|*|
  89. ;---|*| Entry Conditions:
  90. ;---|*|     wParm1 = 0 to setup for mono, 1 to setup for sterero
  91. ;---|*|
  92. ;---|*| Exit Conditions:
  93. ;---|*|     AX,BX,CX,DX modified
  94. ;---|*|
  95. ;   \*/
  96.     public    mvFMInitMode
  97. mvFMInitMode    proc
  98.     push    bp
  99.     mov    bp,sp
  100. ;
  101. ; validate the hardware if not done already.
  102. ;
  103.     cmp    [_MVHWVersionBits],-1    ; check to see if we know the hardware
  104.     jnz    @F
  105.     mov    ax,USE_ACTIVE_ADDR
  106.     push    ax
  107.     call    mvGetHWVersion        ; get the hardware version
  108.     add    sp,2
  109.         cmp     al,-1                   ; everything here?
  110.     jz    mvmfexit        ; no, exit out now...
  111.     ;
  112.     @@:
  113. ;
  114. ; validate the state table pointer
  115. ;
  116.     cmp    word ptr [mvhwShadowPointer+2],0
  117.     jnz    @F
  118.     call    MVInitStatePtr
  119. ;
  120. ; setup I/O delays based upon the installed FM chip
  121. ;
  122.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  123.     jz    @F               ; which are okay, exit out now...
  124.     mov    [indexwrite],3           ; OPL3 index write delays
  125.     mov    [datawrite], 3           ; OPL3 data    write delays
  126. ;
  127. @@:
  128. ;
  129. ; set the chips in mono mode, then flush them.
  130. ;
  131.     sub    ax,ax            ; set the chip(s) in mono mode
  132.     mov    splitmode,al
  133.     call    FMsplit
  134.  
  135.     mov    dx,LFMADDR        ; flush the left/right side
  136.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  137.     call    flushit
  138. ;
  139. ; now, split the chips into stereo mode if requested to do so
  140. ;
  141.     cmp    wptr wParm1,0        ; all done?
  142.     jz    mvmfexit        ; yes, exit
  143.  
  144.     mov    al,1            ; split it now
  145.         mov     splitmode,al
  146.     call    FMsplit
  147. ;
  148. mvmfexit:
  149.     pop    bp
  150.         ret
  151.  
  152. mvFMInitMode    endp
  153.  
  154. ;
  155. ;   /*\
  156. ;---|*|---===< outdual3812(int,int,int) >====----
  157. ;---|*|
  158. ;---|*| This routine writes index/data to
  159. ;---|*| both chips in an interleaved fashion.
  160. ;---|*|
  161. ;---|*| Entry Conditions:
  162. ;---|*|     wParm1 is the chip index value
  163. ;---|*|     wParm2 is the left    FM chip data
  164. ;---|*|     wParm3 is the right FM chip data
  165. ;---|*|
  166. ;---|*| Exit Conditions:
  167. ;---|*|     AX,DX,CX modified
  168. ;---|*|
  169. ;   \*/
  170.  
  171.     public    outdual3812
  172. outdual3812    proc
  173. ;
  174. ; this is kinda screwy, but if we're in mono mode, don't write to both sides
  175. ;
  176.     cmp    splitmode,0        ; are we doing both?
  177.     jjnz    outleft3812        ; no, just do the left side...
  178. ;
  179. ; frame the stack and continue.
  180. ;
  181.     push    bp
  182.     mov    bp,sp
  183. ;
  184. ; write the index to both chips
  185. ;
  186.         mov     dx,LFMADDR              ; get the left 3812 address
  187.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  188.         mov     al,wParm1               ; get the index value
  189. ;
  190. ; special case the OPL3 since it only really has one index register.
  191. ;
  192.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  193.     jnz    outtoopl3           ; which are okay, exit out now...
  194. ;
  195. ; the dual 3812s can have interleaved I/O to speed up the pace
  196. ;
  197.     out    dx,al            ; output to both chips
  198.     add    dx,2
  199.     out    dx,al
  200. ;
  201. ; wait the proper delays for either FM chip
  202. ;
  203.     mov    cx,[indexwrite]
  204.     ;
  205.     @@:
  206.         in      al,dx
  207.     loop    @B
  208. ;
  209. ; write the data out to the chip now
  210. ;
  211.     dec    dx            ; move back to the left FM data reg
  212.     mov    al,byte ptr wParm2
  213.     mov    ah,byte ptr wParm3
  214.  
  215.     out    dx,al            ; write the data out
  216.     add    dx,2
  217.     xchg    ah,al
  218.     out    dx,al
  219. ;
  220. ; wait the proper delays for either FM chip
  221. ;
  222.     mov    cx,[datawrite]
  223.     ;
  224.     @@:
  225.     in    al,dx
  226.     loop    @B
  227.  
  228.     pop    bp
  229.     ret
  230. ;
  231. outtoopl3:
  232. ;
  233. ; do the left side of the OPL3 first
  234. ;
  235.     ; write the left index
  236.  
  237.         out     dx,al                   ; output to both chips
  238.     mov    cx,[indexwrite]
  239.     ;
  240.     @@:
  241.         in      al,dx
  242.     loop    @B
  243.  
  244.     ; write the left data
  245.  
  246.         inc     dx                      ; move to the left FM data reg
  247.     mov    al,wParm2
  248.     out    dx,al            ; write the data out
  249.     mov    cx,[datawrite]
  250.     ;
  251.     @@:
  252.     in    al,dx
  253.     loop    @B
  254. ;
  255. ; do the right side of the OPL3 next
  256. ;
  257.     ; write the right index
  258.  
  259.     inc    dx
  260.         mov     ax,wParm1               ; get the index value
  261.         out     dx,al                   ; output to both chips
  262.     mov    cx,[indexwrite]
  263.     ;
  264.     @@:
  265.         in      al,dx
  266.     loop    @B
  267.  
  268.     ; write the right data
  269.  
  270.         inc     dx                      ; move to the left FM data reg
  271.     mov    al,wParm3
  272.  
  273.     out    dx,al            ; write the data out
  274.     mov    cx,[datawrite]
  275.     ;
  276.     @@:
  277.     in    al,dx
  278.     loop    @B
  279.  
  280.     pop    bp
  281.     ret
  282.  
  283. outdual3812    endp
  284.  
  285. ;
  286. ;   /*\
  287. ;---|*|---===< outleft3812(int,int) >====----
  288. ;---|*|
  289. ;---|*| This routine writes index/data to the left FM chip.
  290. ;---|*|
  291. ;---|*| Entry Conditions:
  292. ;---|*|     wParm1 is the left FM index
  293. ;---|*|     wParm2 is the left FM chip data
  294. ;---|*|
  295. ;---|*| Exit Conditions:
  296. ;---|*|     AX,DX,CX modified
  297. ;---|*|
  298. ;   \*/
  299.  
  300.     public    outleft3812
  301. outleft3812    proc
  302.     push    bp
  303.     mov    bp,sp
  304. ;
  305. ; write the index to both chips
  306. ;
  307.         mov     dx,LFMADDR              ; get the left 3812 address
  308.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  309. ;
  310. fm_common_output label near
  311. ;
  312. ; output the index to the single chip
  313. ;
  314.         mov     ax,wParm1               ; get the index value
  315.     out    dx,al            ; output to both chips
  316.     mov    cx,[indexwrite]
  317. ;
  318. @@:
  319.         in      al,dx                   ; slow down for the index to settle
  320.     loop    @B
  321.  
  322.     inc    dx            ; move to the data register
  323.  
  324.         mov     ax,wParm2
  325.     out    dx,al            ; write the data out
  326.  
  327.     mov    cx,[datawrite]
  328. ;
  329. @@:
  330.     in    al,dx
  331.     loop    @B
  332.  
  333.     pop    bp
  334.     ret
  335.  
  336. outleft3812    endp
  337.  
  338. ;
  339. ;   /*\
  340. ;---|*|---===< outright3812(int,int) >====----
  341. ;---|*|
  342. ;---|*| This routine writes index/data to the right FM chip.
  343. ;---|*|
  344. ;---|*| Entry Conditions:
  345. ;---|*|     wParm1 is the right FM index
  346. ;---|*|     wParm1 is the right FM chip data
  347. ;---|*|
  348. ;---|*| Exit Conditions:
  349. ;---|*|     AX,DX,CX modified
  350. ;---|*|
  351. ;   \*/
  352.  
  353.     public    outright3812
  354. outright3812    proc
  355.     push    bp
  356.     mov    bp,sp
  357. ;
  358. ; write the index to both chips
  359. ;
  360.     mov    dx,RFMADDR        ; get the right 3812 address
  361.         xor     dx,[_MVTranslateCode]   ; translate to the board address
  362.         jmp     short fm_common_output
  363.  
  364. outright3812    endp
  365.  
  366. ;
  367. ;--------------------------==========================--------------------------
  368. ;--------------------------====< local routines >====--------------------------
  369. ;--------------------------==========================--------------------------
  370. ;
  371.  
  372. ;
  373. ;   /*\
  374. ;---|*|---===< flushit >====----
  375. ;---|*|
  376. ;---|*| Reset both sides of the FM chip(s)
  377. ;---|*|
  378. ;---|*| Entry Conditions:
  379. ;---|*|     none
  380. ;---|*|
  381. ;---|*| Exit Conditions:
  382. ;---|*|     AX,BX,CX,DX modified
  383. ;---|*|
  384. ;   \*/
  385. ;
  386. flushit proc    near
  387.     mov    ax,1        ; reg 1
  388.     call    fmout
  389.  
  390.         inc     ax              ; reg 2
  391.     call    fmout
  392.  
  393.         inc     ax              ; reg 3
  394.     call    fmout
  395.  
  396.         inc     ax              ; reg 4
  397.     call    fmout
  398.  
  399.         mov     al,8            ; reg 8
  400.     call    fmout
  401.  
  402.         mov     al,20h          ; flush all others from reg 20 to reg FF
  403.     mov    cx,0FFh-20h
  404. ;
  405. @@:
  406.     call    fmout
  407.     inc    ax
  408.     loop    @B
  409.  
  410.     ret
  411.  
  412. flushit endp
  413.  
  414. ;
  415. ;   /*\
  416. ;---|*|---===< FMsplit >====----
  417. ;---|*|
  418. ;---|*| Split or combine the FM sides.
  419. ;---|*|
  420. ;---|*| Entry Conditions:
  421. ;---|*|     AL = 1 for stereo, 0 for mono
  422. ;---|*|
  423. ;---|*| Exit Conditions:
  424. ;---|*|     AX,BX,CX,DX modified
  425. ;---|*|
  426. ;   \*/
  427. ;
  428. FMsplit proc    near
  429. ;
  430. ; record either MONO or STEREO in the state table
  431. ;
  432.     push    es
  433.     push    di
  434.     les    di,[mvhwShadowPointer]       ; we have to record in in the state
  435. ;
  436. ; maintain the split state fact in the old split FM bit
  437. ;
  438.     mov    ah,al                 ; save an original copy
  439.     cmp    al,1                 ; set carry if zero
  440.     sbb    al,al                 ; al = FF for mono
  441.     and    al,bMImonofm             ; keep the bit if mono
  442.  
  443.         and     es:[di._audiomixr],NOT bMImonofm ; flush the bit
  444.     or    es:[di._audiomixr],al         ; maybe set it
  445.     mov    al,es:[di._audiomixr]         ; load a copy for old pas
  446.  
  447.     pop    di
  448.     pop    es
  449. ;
  450. ; if OPL3, go do it's split, else just write out the new mixer setting
  451. ;
  452.         test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  453.     jnz    splitopl3           ; which are okay, exit out now...
  454.  
  455.     mov    dx,AUDIOMIXR           ; get the mixer address
  456.     xor    dx,[_MVTranslateCode]       ; translate to the board address
  457.     out    dx,al               ; send the bits out to the h/w
  458.  
  459.         ret
  460. ;
  461. splitopl3:
  462.     mov    al,5               ; send it to the right FM reg 5
  463.     mov    dx,RFMADDR
  464.         xor     dx,[_MVTranslateCode]      ; translate to the board address
  465.     out    dx,al               ; send the index
  466.  
  467.         mov     cx,[indexwrite]
  468.     ;
  469.     @@:
  470.     in    al,dx               ; wait the prescribed period
  471.     loop    @B
  472.  
  473.     inc    dx
  474.         mov     al,ah
  475.     out    dx,al               ; send the data byte
  476.  
  477.         mov     cx,[datawrite]
  478.     ;
  479.     @@:
  480.     in    al,dx               ; wait the prescribed period
  481.     loop    @B
  482.  
  483.         ret
  484.  
  485. FMsplit endp
  486.  
  487. ;
  488. ;   /*\
  489. ;---|*|---===< fmout >====----
  490. ;---|*|
  491. ;---|*| write to one of the chips.
  492. ;---|*|
  493. ;---|*| Entry Conditions:
  494. ;---|*|     DX holds the base address (left side or right side)
  495. ;---|*|     AL holds the index register value
  496. ;---|*|     AH holds the data  register value
  497. ;---|*|
  498. ;---|*| Exit Conditions:
  499. ;---|*|     no registers modified
  500. ;---|*|
  501. ;   \*/
  502. ;
  503. fmout   proc    near
  504.     push    ax
  505.     push    cx
  506.  
  507.     out    dx,al
  508.     mov    cx,[indexwrite]
  509. ;
  510. @@:
  511.     in    al,dx
  512.     loop    @B
  513.  
  514.     xchg    ah,al
  515.     inc    dx
  516.     out    dx,al
  517.  
  518.         mov     cx,[datawrite]
  519. ;
  520. @@:
  521.     in    al,dx
  522.     loop    @B
  523.  
  524.     dec    dx
  525.  
  526.     pop    cx
  527.     pop    ax
  528.     ret
  529.  
  530. fmout    endp
  531.  
  532.         end
  533.  
  534.